<h2>Work Search: Beta</h2>

<ul class="navigation" role="navigation"><li>
  <%= link_to(ts("Advanced search"), search_index_path(:query => @query)) %>
</li></ul>

<% unless @query.blank? %>
<p>
  <%= ts('You searched for') %>:
  <% unless @query[:text].blank? %><%= ts('Text') %>: <%= @query[:text] %> <% end %>
  <% unless @query[:tag].blank? %><%= ts('Tag') %>: <%= @query[:tag] %> <% end %>
  <% unless @query[:title].blank? %><%= ts('Title') %>: <%=  @query[:title] %> <% end %>
  <% unless @query[:author].blank? %><%= ts('Author') %>: <%= @query[:author] %> <% end %>
  <% unless @query[:words].blank? %><%= ts('Words') %>: <%= @query[:words] %> <% end %>
  <% unless @query[:hits].blank? %><%= ts('Hits') %>: <%= @query[:hits] %> <% end %>
  <% unless @query[:kudos].blank? %><%= ts('Kudos') %>: <%= @query[:kudos] %> <% end %>
  <% unless @query[:date].blank? %><%= ts('Date') %>: <%= @query[:date] %> <% end %>
  <% unless @query[:language].blank? %><%= ts('Language') %>: <%= @query[:language] %> <% end %>
  <% unless @query[:bookmarked].blank? %><%= ts('Bookmarked') %><% end %>
  <% unless @query[:recced].blank? %><%= ts('Recced') %><% end %>
<% end %>
</p>

<%= form_tag url_for(:controller => 'works', :action => 'search'), :class => 'search', :method => :get do %>
<fieldset>
  <legend>Search works</legend>
  <% unless @query %>
  <% @query ||= {} %>
  <% end %>
    <%= text_field_tag "query[text]", @query[:text], :id => 'refine_text' %>
    <%= link_to_help "work-search-text-help" %> (any field)

  <%= hidden_field_tag "query[tag]", @query[:tag] %>
  <%= hidden_field_tag "query[title]", @query[:title] %>
  <%= hidden_field_tag "query[author]", @query[:author] %>
  <%= hidden_field_tag "query[words]", @query[:words] %>
  <%= hidden_field_tag "query[hits]", @query[:hits] %>
  <%= hidden_field_tag "query[kudos]", @query[:kudos] %>
  <%= hidden_field_tag "query[date]", @query[:date] %>
  <%= hidden_field_tag "query[language]", @query[:language] %>
  <%= hidden_field_tag "query[bookmarked]", @query[:bookmarked] %>
  <%= hidden_field_tag "query[recced]", @query[:recced] %>

  <span class="submit">
<% if @query.blank? %>
    <%= submit_tag ts('Search'), :class => 'button', :name => nil %>
<% else %>
    <%= submit_tag ts('Refine search'), :class => 'button', :name => nil %>
<% end %>
  </span>
</fieldset>
<% end %>

<% if @works %>
<% begin %>
  <p><strong><%= @works.total_entries %> Found</strong><%= link_to_help "work-search-results-help" %></p>

  <h3 class="landmark">Works List</h3>
  <ol class="work index">
    <% @works.each do |work| %>
      <% unless work.nil? %>
        <%= render :partial => 'work_blurb', :locals => {:work => work} %>
      <% end %>
    <% end %>
  </ol>
  <div class="clear"><!-- presentational--></div>
  <%= will_paginate @works, {:previous_label => '&laquo; Previous', :next_label => 'Next &raquo;'} %>
<% rescue Riddle::ConnectionError %>
   <%= ts("The search engine seems to be down at the moment, try back later!")%>
  <% end %>
<% end %>
